package com.example.service.impl;

import com.example.mapper.afterSalesFaultPartsMapp;
import com.example.pojo.afterSalesFaultPartsPojo;
import com.example.service.afterSalesFaultPartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:afterSalesFaultPartsImpl
 * Package:com.example.service.impl
 * Description:
 *
 * @Author：牧星苑
 * @Create 2025/10/8 16:09
 * @Version 1.0
 */
@Service
public class afterSalesFaultPartsImpl implements afterSalesFaultPartsService {
    @Autowired
    private afterSalesFaultPartsMapp afterSalesFaultPartsMapp;
    //根据分页查询返件清单
    public List<afterSalesFaultPartsPojo> queryByPage(Map<String, Object> map){
        Integer page =(Integer) map.get("page");
        Integer size=(Integer) map.get("size");
        Integer startRow=page*size;
        List<afterSalesFaultPartsPojo> afterSalesFaultPartsPojos=afterSalesFaultPartsMapp.queryByPage(startRow, size);
        return afterSalesFaultPartsPojos;
    }

    //查询所有返件清单条数
    public Integer queryQuantity(){
        Integer quantity= afterSalesFaultPartsMapp.queryQuantity();
        return quantity;
    }

    //插入一行返件清单
    public void insertOne(afterSalesFaultPartsPojo pojo){
        pojo.setCreate_time(LocalDateTime.now());
        pojo.setUpdate_time(LocalDateTime.now());
        afterSalesFaultPartsMapp.insertOne(pojo);
    }

    //修改一行返件清单
    public void editOneById(afterSalesFaultPartsPojo pojo){
        pojo.setUpdate_time(LocalDateTime.now());
        afterSalesFaultPartsMapp.editOneById(pojo);
    }

    //动态查询返件清单
    public List<afterSalesFaultPartsPojo> queryByDynamicConditions(Map<String, Object> map){
        return afterSalesFaultPartsMapp.queryByDynamicConditions(map);
    }

    //查询所有返件清单
    public List<afterSalesFaultPartsPojo> queryAll(){
        List<afterSalesFaultPartsPojo> pojoList = afterSalesFaultPartsMapp.queryAll();
        return pojoList;
    }

    //修改返件清单一个字段.依据索赔单关联id
    public void editOneField(Map<String, Object> map){
        Integer warranty_claim_id = (Integer) map.get("warranty_claim_id");
        String firstFieldName = (String) map.get("firstFieldName");
        Integer firstFieldValue = (Integer) map.get("firstFieldValue");
        LocalDateTime update_time=LocalDateTime.now();
        afterSalesFaultPartsMapp.editOneField(warranty_claim_id,firstFieldName,firstFieldValue,update_time);
    }
    //修改返件清单一个字段.依据索赔单关联id
    public void editOneFieldCBU(Map<String, Object> map){
        String warranty_claim_CBU_id = (String) map.get("warranty_claim_CBU_id");
        String firstFieldName = (String) map.get("firstFieldName");
        Integer firstFieldValue = (Integer) map.get("firstFieldValue");
        LocalDateTime update_time=LocalDateTime.now();
        afterSalesFaultPartsMapp.editOneFieldCBU(warranty_claim_CBU_id,firstFieldName,firstFieldValue,update_time);
    }
    //修改返件清单一个字段.依据索赔单关联id
    public void editOneFieldKD(Map<String, Object> map){
        String warranty_claim_KD_id = (String) map.get("warranty_claim_KD_id");
        String firstFieldName = (String) map.get("firstFieldName");
        Integer firstFieldValue = (Integer) map.get("firstFieldValue");
        LocalDateTime update_time=LocalDateTime.now();
        afterSalesFaultPartsMapp.editOneFieldKD(warranty_claim_KD_id,firstFieldName,firstFieldValue,update_time);
    }
}
